<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="/publico/template.xhtml">
        <ui:define name="content">
            <p:messages/>

            <h:form id="fprincipal">
                <p:panel id="pprincipal" 
                         header="Caracterização">
                    <h:panelGrid id="pgprincipal"
                                 columns="2">
                        <h:outputLabel for="itlote"
                                       value="Lote: "/>
                        <p:inputText id="itlote" 
                                     value="#{processoBean.processo.id}"
                                     readonly="true"/>

                        <h:outputLabel for="sonutriente"
                                       value="Nutriente: "/>
                        <h:selectOneMenu id="sonutriente" 
                                         value="#{processoBean.caracterizacao.nutriente}"
                                         converter="NutrienteConversor">
                            <f:selectItems value="#{nutrienteBean.nutrientes}"
                                           var="n"
                                           itemLabel="#{n.nome}"
                                           itemValue="#{n}"/>
                        </h:selectOneMenu>

                        <h:outputLabel for="itquantidade"
                                       value="Quantidade: "/>
                        <p:inputText id="itquantidade" 
                                     value="#{processoBean.caracterizacao.quantidade}"/>
                    </h:panelGrid>

                    <p:commandButton id="cbsalvar"
                                     value="Adicionar"
                                     action="#{processoBean.salvarCaracterizacao}"
                                     update="@form, :fcaracterizacao"/>
                    
                    <p:button value="Voltar"
                              outcome="/restrito/lote/informacao-lote.xhtml"/>
                </p:panel>
            </h:form>

            <h:form id="fcaracterizacao">
                <p:panel>
                    <p:dataTable  value="#{processoBean.caracterizacoes}" 
                                  var="c"
                                  emptyMessage="sem dados">
                        <p:column headerText="Id">
                            <h:outputLabel value="#{c.id}"/>
                        </p:column>

                        <p:column headerText="Nutriente">
                            <h:outputLabel value="#{c.nutriente.nome}"/>
                        </p:column>

                        <p:column headerText="Quantidade">
                            <h:outputLabel value="#{c.quantidade}"/>
                        </p:column>

                        <p:column headerText="Opções">
                            <p:commandButton 
                                onclick="return confirm('Você tem certeza?')"
                                action="#{processoBean.removerCaracterizacao()}"
                                value="Excluir"
                                update="@form">
                                <f:setPropertyActionListener 
                                    target="#{processoBean.caracterizacao}"
                                    value="#{c}"/>
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
